package com.paranoid.flashcard.logic;

import android.app.IntentService;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.paranoid.flashcard.dao.QuizletDao;
import com.paranoid.flashcard.model.QuizletDeck;

public class DownloadService extends IntentService {

	public final static String DOWNLOAD_FINISHED_INTENT = "com.paranoid.flashcard.DOWNLOAD_FINISHED_INTENT";
	
	public DownloadService() {
		super("DownloadService");
	}
	
	public void onCreate() {
		super.onCreate();
	}
	
	@Override
	protected void onHandleIntent(Intent intent) {
		Bundle bundle = intent.getExtras();
		QuizletDeck deck = new QuizletDeck();
		deck.id = bundle.getLong("QuizletDeckId");
		deck.title = bundle.getString("QuizletDeckTitle");
		Log.i("", "title: " + deck.title + ", id: " + deck.id);
		QuizletDao.getInstance().importDeckToDb(deck);
		Intent i = new Intent();
		i.setAction(DOWNLOAD_FINISHED_INTENT);
		sendBroadcast(i);
	}
}
